<?php
class VerifyPkgResponseHandler extends Fs2PostHandler
{

    /**
     * @see SzAbstractCtrlPostProcessHandler::handle
     *
     * @param array $inputs passed by reference, params inputted from $_REQUEST['*']
     * @return boolean
     */
    public function handle($inputs)
    {
        if ($this->checkHandleExclude($inputs)) {
            return true;
        }

        $pkgIndex = SzParam::getReqParam('pkgIndex', 0);
        if ($pkgIndex == 0) {
            return true;
        }

        $userId = $this->parseUserId($inputs);
        $resManager = serialize(SzController::get()->getResManager());

        $handle = SzContextFactory::get()->getStaticCache($userId);
        $redisKey = GameConst::CACHE_KEY_PKG_INDEX . $userId;

        $hashKeys = $handle->hKeys(GameConst::CACHE_KEY_PKG_INDEX . $userId);
        if (count($hashKeys) >= GameConst::CACHE_PKG_INDEX_MAX) {
            //删除最小的hashFiled
            $handle->hDel($redisKey, min($hashKeys));
        }
        $handle->hSet($redisKey, $pkgIndex, $resManager, SzTime::MINUTE * 5);
        return true;
    }
}